<?
require_once('config.php');
$current_page = getValue('page','int','GET',1);
$alb_id       = getValue('alb_id','int','GET',0);
$action       = getValue('action','str','GET','');
$limit_page   = 20;
$start        = ($current_page -1) * $limit_page;
$limit        = $start . ',' . $limit_page;

$arr_albums   = xinh_albums::getListAlbum();
$total_albums = xinh_albums::getTotalAlbums();
$pages = ceil($total_albums/$limit_page);
/*----------------- Xử lý phân trang --------------------*/

$count_alb = count($arr_albums); 



?>
<?=$css_global?>
<?=$js_global?>
<div class="row-fluid">
   <div class="head">
      <div class="isw-grid"></div>
      <h1>Danh sách album</h1>
      <div class="reload_tab" title="Reload"></div>                              
      <div class="clear"></div>
   </div>                                
   <div class="block-fluid table-sorting">
      <div id="tSortable_wrapper" class="dataTables_wrapper" >
         <div class="dataTables_filter" id="tSortable_filter">
               <div class="head-table">
                  <ul class="title-table pull-left">
                     <li>Tổng số: <?=$total_albums?></li>
                     <li>Trang số: <?=$current_page?></li>
                     <li>Mỗi trang: <?=$limit_page?></li>
                  </ul>     
               </div>
         </div>
         <table cellpadding="0" cellspacing="0" width="100%" class="table dataTable table-bordered" id="tSortable"  style="width: 100%;">
            <thead>
              <tr>
                  <th class="sorting_disabled selectallrow active"  rowspan="1" colspan="1" style="width: 23px;">Tất cả</th>
                  <th width="5%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">ID</th>
                  <th width="15%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Ngày</th>
                  <th width="15%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Tên album</th>
                  <th width="10%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Thể loại</th>
                  <th width="10%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Ảnh</th>
                  <th width="5%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Active</th>
                  <th width="25%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Thêm ảnh</th>
                  <th width="5%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">View</th>
                  <th width="5%" class="sorting" tabindex="0" rowspan="1" colspan="1" style="">Like</th>
                  
               </tr>
            </thead>
              <?
              if($count_alb > 0){
                  foreach($arr_albums as $value){
                     $image = xinh_albums::getAvatar($value['id']);
                  ?>
                     <tr class="even" data-id=<?=$value['id']?>>
                        <td class="font12 sorting_1">
                           <div class="checker check-to-delete">
                              <span>
                                 <input type="checkbox" class="checkbox-row" name="row_to_delete[]" value="<?=$value['id']?>" style="opacity: 0;"/>
                              </span>
                           </div>
                        </td>
                        <td class="font12"><?=$value['id']?></td>
                        <td class="font12"><?=date('H:m:s - d/m/Y',$value['date'])?></td>
                        <td class="font12"><?=$value['name']?> (<b style="color: #06F;"><?=xinh_albums::getTotalImageInAlbum($value['id'])?> ảnh</b>)</td>
                        <td class="font12"><?=$array_cate[$value['cat_id']]?></td>
                        <td class="font12 alb-name"><img width="60px" class="img-person" src="<?=$image?>" /></td>       
                        <td class="font12 sorting_1" onclick="activeAlbum(this)">
                           <div class="checker">
                              <span active="<?=$value['active']?>" class="<?if($value['active'] == 1) echo 'checked';?>">
                                 <input type="checkbox" class="active-row" data-id=<?=$value['id']?>  value="<?=$value['active']?>"/>
                              </span>
                           </div>
                        </td> 
                        <td class="font12">
                           <input class="span10" name="alb-<?=$value['id']?>" id="alb-<?=$value['id']?>" placeholder="Nhập link ảnh rồi ấn thêm" />
                           <span class="btn btn-success" onclick="addImageToAlbum(<?=$value['id']?>)">Thêm</span>
                        </td>
                        <td class="font12"><?=$value['view']?></td>
                        <td class="font12"><?=$value['alike']?></td>
                                             
                    </tr>
                  <?}?>
              <?}?>
          </table>
         </div>
      <div class="clear"></div>
      <div class="mult_submit pull-left">
         <span>Với những dòng đã chọn: </span>  <span class="delete-row mult-delete">Xóa</span> 
      </div>
      <div class="paging pull-right">
         <?php $pagination = pagination($current_page,$pages,'list_albums.php?page=%d') ?>
         <ul>
         <?php foreach ($pagination as $link): ?>
           <li><?php echo $link ?></li>
         <?php endforeach ?>
         </ul>
      </div>
   </div>
</div>
<script>
$(function(){
   $('.mult-delete').click(function(){
      var matches = [];
      $(".checkbox-row:checked").each(function() {
          matches.push(this.value);
          string_cat_id = matches.join(',');
      });
      data = {'id':string_cat_id};
      var updateHTML = function(data){
         if(data != ''){
            alert(data);
            window.location.reload();
         }
      }
      var beforeSend = function(){
         
      }
      var conf = confirm("Xóa những dòng đã chọn ?");
      if(conf)
         handleAjax('delete.php','POST',data,updateHTML,beforeSend);
   });
});
</script>